<include file="Public:header" />
<div class="container">
	<!-- Docs nav ================================================== -->
	<div class="page-header" style="border:none; font-size:14px;">
		<ul class="nav nav-tabs">
		  <li><a  href="{:U('customer/index')}"><img src="__PUBLIC__/img/customer_icon.png"/>&nbsp; {:L('CUSTOMER')}</a></li>
		  <li><a  href="{:U('customer/index','content=resource')}"><img src="__PUBLIC__/img/customer_source_icon.png"/>&nbsp; {:L('CUSTOMER POOL')}</a></li>
		  <li class="active"><a href="{:U('contacts/index')}"><img src="__PUBLIC__/img/contacts_icon.png"/> &nbsp;{:L('CONTACTS')}</a></li>
		  <li><a href="{:U('customer/cares')}"><img src="__PUBLIC__/img/cares_icon.png"/> &nbsp;{:L('CARES')}</a></li>
		  <li><a href="{:U('customer/analytics')}"><img src="__PUBLIC__/img/tongji.png"/> &nbsp;{:L('THE CUSTOMER STATISTICS')}</a></li>
		  <li><a href="http://5kcrm.com/index.php?m=doc&a=index&id=27" target="_blank" style="font-size: 12px;color: rgb(255, 102, 0);"><img width="20px;" src="__PUBLIC__/img/help.png"/> {:L('HELP')}</a></li>
		</ul>
	</div>
	<include file="Public:alert" />
	<p class="view">
		<b> {:L('THE CONTACTS VIEW')}</b>
		<img src=" __PUBLIC__/img/by_owner.png"/> <a href="{:U('contacts/index')}" <if condition="$Think.get.by eq null">class="active"</if>>{:L('ALL')}</a> |
		<img src="__PUBLIC__/img/by_time.png"/> 
		<a href="{:U('contacts/index','by=today')}" <if condition="$Think.get.by eq 'today'">class="active"</if>>{:L('TODAY TO ADD')}</a> | 
		<a href="{:U('contacts/index','by=week')}" <if condition="$Think.get.by eq 'week'">class="active"</if>>{:L('WEEK TO ADD')}</a> | 
		<a href="{:U('contacts/index','by=month')}" <if condition="$Think.get.by eq 'month'">class="active"</if>>{:L('MONTH TO ADD')}</a>   &nbsp;  
		
		<a href="{:U('contacts/index','by=add')}" <if condition="$Think.get.by eq 'add'">class="active"</if>>{:L('RECENTLY_CREATED')}</a> | 
		<a href="{:U('contacts/index','by=update')}" <if condition="$Think.get.by eq 'update'">class="active"</if>>{:L('RECENT_UPDATES')}</a> &nbsp;  &nbsp; 
		<a href="{:U('contacts/index','by=deleted')}" <if condition="$Think.get.by eq 'deleted'">class="active"</if>><img src="__PUBLIC__/img/task_garbage.png"/> {:L('RECYCLE_BIN')}</a> 
	</p>
	<div class="row">
		<div class="span12">
			<ul class="nav pull-left">
				<if condition="$Think.session.admin eq 1 or $Think.get.by neq 'deleted'">
				<li class="pull-left"><a id="delete"  class="btn" style="margin-right: 8px;"><i class="icon-remove"></i>{:L('DELETE')}</a></li>
				</if>
				<li class="pull-left">
				<form class="form-inline" id="searchForm" action="index.php" method="get">
					<ul class="nav pull-left">
						<li class="pull-left">
							<select style="width:auto" id="field" name="field" onchange="changeCondition()">
								<option class="all" value="all">{:L('ANY_FIELD')}</option>
								<option class="word" value="name">{:L('CONTACT_NAME')}</option>
								<option class="word" value="customer_name">{:L('CUSTOMER')}</option>
								<option class="word" value="telephone">{:L('PHONE')}</option>
								<option class="word" value="qq">QQ</option>
								<option class="word" value="saltname">{:L('RESPECTFULLY')}</option>
								<option class="word" value="email">{:L('EMAIL')}</option>
								<option class="word" value="address">{:L('ADDRESS')}</option>
								<option class="word" value="post">{:L('POSITION')}</option>
								<option class="word" value="description">{:L('REMARK')}</option>
								<option class="date" value="create_time">{:L('CREATE_TIME')}</option>
								<option class="date" value="update_time">{:L('UPDATE_TIME')}</option>
							</select>&nbsp;&nbsp;
						</li>
						<li id="conditionContent" class="pull-left">
							<select id="condition" style="width:auto" name="condition" onchange="changeSearch()">
								<option value="contains">{:L('CONTAINS')}</option>
								<option value="not_contain">{:L('NOT_CONTAIN')}</option>
								<option value="is">{:L('IS')}</option>
								<option value="isnot">{:L('ISNOT')}</option>						
								<option value="start_with">{:L('START_WITH')}</option>
								<option value="end_with">{:L('END_WITH')}</option>
								<option value="is_empty">{:L('IS_EMPTY')}</option>
								<option value="is_not_empty">{:L('IS_NOT_EMPTY')}</option>
							</select>&nbsp;&nbsp;
						</li>
						<li id="searchContent" class="pull-left">
							<input id="search" type="text" class="input-medium search-query" name="search"/>&nbsp;&nbsp;
						</li>
						<li class="pull-left">
							<input type="hidden" name="m" value="contacts"/>
							<input type="hidden" id="act" name="act" value="search"/>
							<if condition="$Think.get.by neq null"><input type="hidden" name="by" value="{$Think.get.by}"/></if>
							<button type="submit" class="btn"> <img src="__PUBLIC__/img/search.png"/>  {:L('SEARCH')} </button>&nbsp;&nbsp;
						</li>
						<li class="pull-left">
							<div class="btn-group" style="margin-right:5px;">
								<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
									<img src="__PUBLIC__/img/sms.png"></img>{:L('SEND_SMS')}
									<span class="caret"></span>
								</a>
								
								<ul class="dropdown-menu">
									<li><a id="page_send" href="javascript:void(0)">{:L('PAGE_SEND')}</a></li>
									<li><a id="check_send" href="javascript:void(0)">{:L('CHECK_SEND')}</a></li>
								</ul>
							</div>
							<div class="btn-group">
								<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
									<img src="__PUBLIC__/img/email.png"></img>&nbsp;{:L('SEND_EMAIL')}
									<span class="caret"></span>
								</a>
								<ul class="dropdown-menu">
									<li><a id="page_send_email" href="javascript:void(0)">{:L('PAGE_SEND')}</a></li>
									<li><a id="check_send_email" href="javascript:void(0)">{:L('CHECK_SEND')}</a></li>
								</ul>
							</div>
						</li>
					</ul>
				</form>
				</li>
			</ul>
			<div class="row pull-right">
				<a href="{:U('contacts/add')}" class="btn btn-primary"><i class="icon-plus">&nbsp; {:L('NEW_LINK')}</i></a>&nbsp;
				<!-- 被客户导入导出替代，暂时无用
				<div class="btn-group">
					<button class="btn btn-primary dropdown-toggle" data-toggle="dropdown"> <i class="icon-wrench"> &nbsp; {:L('CONTACT_TOOLS')} </i><span class="caret"></span></button>
					<ul class="dropdown-menu">
						<li><a href="javascript:return(0);" id="import_excel"  class="link"><i class="icon-upload"> &nbsp;{:L('IMPORT_CONTACTS')}</i></a></li>
						<li><a href="javascript:void(0);" id="excelExport" class="link"><i class="icon-download"> &nbsp;{:L('EXPORT_CONTACT')}</i></a></li>
					</ul>
				</div>
				-->
			</div>
		</div>
		<div class="span12">
			<form id="form1" action="" method="post">
				<table class="table table-hover table-striped table_thead_fixed">
					<if condition="$contactsList eq null">
						<tr><td>{:L('EMPTY_TPL_DATA')}</td></tr>
					<else/>
						<thead>
							<tr>
								<th><input class="check_all" id="check_all" type="checkbox" /> &nbsp;</th>
								<th>{:L('CONTACT_NAME')}</th>
								<if condition="C('ismobile') neq 1"><th>{:L('RESPECTFULLY')}</th></if>
								<th>{:L('BELONGS TO THE CUSTOMER')}</th>
								<th>{:L('PHONE')}</th>					
								<if condition="C('ismobile') neq 1">
								<th>QQ</th>
								<th>Email</th></a>
								<th>{:L('CREATOR_ROLE')}</th>
								</if>								
								<th>
									<if condition="$_GET['asc_order'] == 'create_time'">
										<a href="{:U('contacts/index','desc_order=create_time&'.$parameter)}">
											{:L('CREATE_TIME')}&nbsp;<img src="__PUBLIC__/img/arrow_up.png">
										</a>
									<elseif condition="$_GET['desc_order'] == 'create_time'"/>
										<a href="{:U('contacts/index','asc_order=create_time&'.$parameter)}">
											{:L('CREATE_TIME')}&nbsp;<img src="__PUBLIC__/img/arrow_down.png">
										</a>
									<else/>
										<a href="{:U('contacts/index','desc_order=create_time&'.$parameter)}">{:L('CREATE_TIME')}</a>
									</if>
								</th>
								<if condition="(C('ismobile') neq 1) and ($Think.get.by eq 'deleted')"><th>{:L('DELETE_THE_PEOPLE')}</th><th>{:L('DELETE_TIME')}</th></if>
								<th>{:L('OPERATING')}</th>
							</tr>
						</thead>
					 
						<tfoot>
							<tr>
								<if condition="$Think.get.by eq 'deleted'"><tr><td colspan="12">{$page}</td></tr>
								<else /><tr><td colspan="10">{$page}</td></tr>
								</if>
							</tr>
						</tfoot>
						
						<tbody>
							<volist name="contactsList" id="vo">
							<tr>
								<td><input type="checkbox" class="check_list" name="contacts_id[]" value="{$vo.contacts_id}"/>&nbsp;
								</td>
								<td><a href="{:U('contacts/view', 'id='.$vo['contacts_id'])}">{$vo.name}</a></td>
								<if condition="C('ismobile') neq 1"><td>{$vo.saltname}</td></if>
								<td><a href="{:U('customer/view', 'id='.$vo['customer_id'])}">{$vo.customer_name}</a></td>	
								<td><if condition="C('ismobile') neq 1 ">{$vo.telephone}<else /><a href="tel://{$vo.telephone}">{$vo.telephone}</a></if></td>
								<if condition="C('ismobile') neq 1">
								<td>{$vo.qq}</td>
								<td>{$vo.email}</td>
								<td><notempty name="vo.creator.user_name"><a class="role_info" rel="{$vo.creator.role_id}" href="javascript:void(0)">{$vo.creator.user_name}</a></notempty></td>
								<td>{$vo.create_time|date='Y-m-d H:i',###}</td>
								</if>
								<if condition="(C('ismobile') neq 1) and ($Think.get.by eq 'deleted')">
									<td><a class="role_info" rel="{$vo.delete_role.role_id}" href="javascript:void(0)">{$vo.delete_role.user_name}</a></td><td>{$vo.delete_time|date='Y-m-d H:i',###}</td>
								</if>
								<if condition="$Think.get.by eq 'deleted'">
									<td>
										<a href="{:U('contacts/view', 'id='.$vo['contacts_id'])}">{:L('VIEW')}</a>&nbsp;
										<a href="{:U('contacts/revert', 'id='.$vo['contacts_id'])}">{:L('RESET')}</a>
									</td>
								<else />
									<td>
										<a href="{:U('contacts/view', 'id='.$vo['contacts_id'])}">{:L('VIEW')}</a>&nbsp;
										<a href="{:U('contacts/edit', 'id='.$vo['contacts_id'])}">{:L('EDITING')}</a>
									</td>
								</if>
							</tr>
							</volist>
						</tbody>
					</if>
				</table>
			</form>
		</div>
	</div>
</div>
<div class="hide" id="dialog-import" title="{:L('IMPORT_DATA')}">loading...</div>
<div class="hide" id="dialog-role-info" title="{:L('DIALOG_USER_INFO')}">loading...</div>
<script type="text/javascript">
$("#dialog-import").dialog({
	autoOpen: false,
	modal: true,
	width: 600,
	maxHeight: 400,
	position: ["center",100]
});
$("#dialog-role-info").dialog({
    autoOpen: false,
    modal: true,
	width: 600,
	maxHeight: 400,
	position: ["center",100]
});
function changeContent(){
	a = $("#select1  option:selected").val();
	window.location.href="{:U('contacts/index', 'by=')}"+a;
}

$(function(){
<if condition="$Think.get.field neq null">
	$("#field option[value='{$Think.get.field}']").prop("selected", true);changeCondition();
	$("#condition option[value='{$Think.get.condition}']").prop("selected", true);changeSearch();
	$("#search").prop('value', '{$Think.get.search}');
</if>
	$("#check_all").click(function(){
		$("input[class='check_list']").prop('checked', $(this).prop("checked"));
	});
	$('#delete').click(function(){
		if(confirm('{:L('ARE_YOU_SURE_YOU_WANT_TO_DELETE')}')){
		<if condition="$Think.session.admin eq 1 and $Think.get.by eq 'deleted'">
			$("#form1").attr('action', '{:U("contacts/completedelete")}');
			$("#form1").submit();
		<else />
			$("#form1").attr('action', '{:U("contacts/delete")}');
			$("#form1").submit();
		</if>
		}
	});
	$("#import_excel").click(function(){
		$('#dialog-import').dialog('open');
		$('#dialog-import').load('{:U("contacts/excelimport")}');
	});
	$(".role_info").click(function(){
		$role_id = $(this).attr('rel');
		$('#dialog-role-info').dialog('open');
		$('#dialog-role-info').load('{:U("user/dialoginfo","id=")}'+$role_id);
	});
	$("#check_send").click(function(){
		var id_array = new Array();
		$("input[class='check_list']:checked").each(function(){  
			id_array.push($(this).val());
		});
		
		if(id_array.length == 0){
			alert('{:L('YOU_HAVE_NOT_CHOSEN_ANY_CONTACT')}');
		}else{
			var contacts_ids = id_array.join(",");
			window.location.href="{:U('setting/sendSms', 'model=contacts&contacts_ids=')}"+contacts_ids;
		}
	});
	$("#check_send_email").click(function(){
		var id_array = new Array();
		$("input[class='check_list']:checked").each(function(){  
			id_array.push($(this).val());
		});
		
		if(id_array.length == 0){
			alert('{:L('YOU_HAVE_NOT_CHOSEN_ANY_CONTACT')}');
		}else{
			var contacts_ids = id_array.join(",");
			window.location.href="{:U('setting/sendemail', 'model=contacts&contacts_ids=')}"+contacts_ids;
		}
	});
	$("#page_send").click(function(){
		var id_array = new Array();
		$("input[class='check_list']").each(function(){
			id_array.push($(this).val());
		});
		if(id_array.length == 0){
			alert('{:L('YOU_HAVE_NOT_CHOSEN_ANY_CONTACT')}');
		}else{
			var contacts_ids = id_array.join(",");
			window.location.href="{:U('setting/sendSms', 'model=contacts&contacts_ids=')}"+contacts_ids;
		}
	});
	$("#page_send_email").click(function(){
		var id_array = new Array();
		$("input[class='check_list']").each(function(){
			id_array.push($(this).val());
		});
		if(id_array.length == 0){
			alert('{:L('YOU_HAVE_NOT_CHOSEN_ANY_CONTACT')}');
		}else{
			var contacts_ids = id_array.join(",");
			window.location.href="{:U('setting/sendemail', 'model=contacts&contacts_ids=')}"+contacts_ids;
		}
	});
	$("#excelExport").click(function(){
		if(confirm("{:L('CONFIRM_EXPORT_CONTACTS')}")){
			$("#act").val('excel');	
			$("#searchForm").submit();
		}
		$("#act").val('search');	
	})	
})
</script>
<include file="Public:footer" />